<template>
    <section class="review-content">
        <el-card class="content_box" v-loading="contentLoad">
              <div class="unchecked">
                <div class="review_title">
                  <p>未审核数量：</p>
                  <span>{{unFinishList.length}}</span>
                </div>
                <div style="clear: both"></div>
                <div class="unchecked_item" :class="`${item.status == '0' ? 'uncommit' : 'unreview'} ${unactiveIndex == index ? 'active_bgc' : ''}`"  v-for="(item, index) in unFinishList" :key="index" @click="updateIndex(item, index)">
                  {{item.objectName.replace(/党委/,'')}}
                  <div class="mark uncommit_mark" v-if="item.status === '0'" :class="`${unactiveIndex == index&&item.status === '0' ? 'active_uncommit_mark' : ''}`"></div>
                  <div class="mark unreview_mark" v-if="item.status === '1'" :class="`${unactiveIndex == index&&item.status === '1' ? 'active_unreview_mark' : ''}`"></div>
                </div>
              </div>
              <div class="arrow"></div>
              <div class="checked">
                <div class="review_title">
                  <p>已审核数量：</p>
                  <span>{{finishList.length}}</span>
                  <div class="confirm_input">
                    <div class="cofirm_form">
                      <el-form :model="form" :rules="formRules" ref="form" label-width="100px" class="demo-ruleForm">
                          <el-form-item label="确认人" prop="name">
                              <el-input v-model="form.name"  placeholder="请输入确认人姓名"></el-input>
                          </el-form-item>
                      </el-form>
                    </div>
                    <div class="confirmBtn">
                        <el-button type="primary" size="large" :loading="confirmIndexLoading" @click="confirmIndex('form')">确认</el-button>
                    </div>
                  </div>
                </div>
                <div style="clear: both"></div>
                <div class="checked_item" :class="`${activeIndex == index ? 'active_bgc' : ''}`" v-for="(item, index) in finishList" :key="index" @click="updateIndex(item, index)">
                  {{item.objectName.replace(/党委/,'')}}
                  <div class="mark checked_mark" :class="`${activeIndex == index ? 'active_checked_mark' : ''}`"></div>
                </div>
              </div>
              <div style="clear: both"></div>
            <div class="box">
              <div style="margin: 0 0 12px 0">
                  <el-tag size="large" v-if="currentTaskObject.status === '0'" close-transition type="danger" effect="dark" style="width: 220px;text-align: center;float: left">当前状态：待提交</el-tag>
                  <el-tag size="large" v-else-if="currentTaskObject.status === '1'" close-transition  type="warning" effect="dark" style="width: 220px;text-align: center;float: left">当前状态：待市委审核</el-tag>
                  <el-tag size="large" v-else-if="currentTaskObject.status === '2'" close-transition  type="primary" effect="dark" style="width: 220px;text-align: center;float: left">当前状态：待市委确认</el-tag>
                  <el-tag size="large" v-else-if="currentTaskObject.status === '3'" close-transition  type="success" effect="dark" style="width: 220px;text-align: center;float: left">当前状态：市委确认通过</el-tag>
                  <div class="check_button">
                    <el-button size="large" @click="showCheckDialog" :disabled="currentTaskObject.status !== '1'" type="primary">审核</el-button>
                  </div>
                  <p style="clear: both"></p>
              </div>
              <div class="ReviewContent">
                <div class="tabWrap">
                <el-row class="tabNav">
                    <el-col :span="1" id="tabBar">
                      <ul id="tabUl" v-for="(item,index) in tabList" :key="index">
                        <li :class="[{activeTab:index === tabIndex},'tabLi']" @click="changeTab(index, item)">{{item.quotaName}}({{item.quotaScore}}分)</li>
                      </ul>
                    </el-col>
                    <el-col :span="23" class="tabContent">
                      <div v-loading="tabContentLoading" v-if="isSetWeight === '0'" class="tabContent_one">
                        <div class="second_level" v-for="(item, index) in recipet" :key="'info' + index">
                          <el-card>
                            <p class="item_title">{{item.quotaName}}</p>
                            <div class="three_level" >
                              <div v-if="item.kpiTownQuotas.length" >
                                <div class="three_level_item" v-for="(subItem,subIndex) in item.kpiTownQuotas" :key="subIndex">
                                  <div class="three_level_score">
                                    <div v-if="subItem.score">
                                      <span>{{subItem.score}}</span>  分
                                    </div>
                                    <div v-else>
                                      <span></span>
                                    </div>
                                  </div>
                                  <el-tooltip :content="subItem.quotaName" placement="bottom" v-if="subItem.quotaName && subItem.quotaName.length>8">
                                    <div>{{subItem.quotaName ? subItem.quotaName.substring(0,7)+"..." : ''}}</div>
                                  </el-tooltip>
                                  <div v-else>{{subItem.quotaName}}</div>
                                </div>
                              </div>
                              <div v-else class="not_available">
                                <p>暂无</p>
                              </div>
                            </div>
                          </el-card>
                        </div>
                      </div>
                      <div v-loading="tabContentLoading" v-if="isSetWeight === '1'" class="tabContent_one">
                        <div class="second_level_day" v-for="(item, index) in recipet" :key="'info' + index">
                          <el-card shadow="never">
                            <p class="item_title">{{item.quotaName}}</p>
                            <div class="table_box" style=" overflow: auto;min-height: 400px ">
                              <table v-if="JSON.stringify(item.kpiTownQuotas) !== '[]'" class="actual_table" border="1" cellspacing="0" cellpadding="0">
                                <tr height="50px">
                                  <td>
                                    <div style="width: 198px">指标</div>
                                  </td>
                                  <td>
                                    <div style="width: 50px">分值</div>
                                  </td>
                                  <td v-for="subitem in townsList[currentTaskObject.objectName].orgChildren" :key="subitem.index">
                                  <el-tooltip :content="subitem.districtName" placement="top" v-if="subitem.districtName && subitem.districtName.length>5">
                                        <div style="width: 100px">{{subitem.districtName ? subitem.districtName.substring(0,4)+"..." : ''}}</div>
                                    </el-tooltip>
                                    <div v-else style="width: 100px">{{subitem.districtName}}</div>
                                  </td>
                                </tr>
                                <tr height="50px" v-if="item.kpiTownQuotas" v-for="(subItem,subIndex) in item.kpiTownQuotas" :key="subIndex">
                                  <td>
                                    <el-tooltip :content="subItem.quotaName" placement="top" v-if="subItem.quotaName && subItem.quotaName.length>11">
                                        <div>{{subItem.quotaName ? subItem.quotaName.substring(0,10)+"..." : ''}}</div>
                                    </el-tooltip>
                                    <div v-else>{{subItem.quotaName}}</div>
                                  </td>
                                  <td style="color: #fd4b63; font-weight: 700;">{{subItem.score ? subItem.score : 0}}</td>
                                  <td style="color: #0692eb; font-weight: 700;" v-for="(weightItem, weightIndex) in subItem.kpiVillageQuotas" :key="weightIndex">
                                    {{weightItem.weight ? weightItem.weight : 0}}
                                  </td>
                                </tr>
                              </table>
                              <div v-else class="not_available">
                                <p>暂无</p>
                              </div>
                            </div>
                          </el-card>
                        </div>
                      </div>
                    </el-col>
                  </el-row>
                </div>
              </div>
            </div>
            <el-dialog
              title="审核"
              :visible.sync="checkVisible"
              width="50%"
              append-to-body>
              <el-row style="margin-top: 5px" v-show="currentTaskObject.status === '1'">
                <el-col :span="2">
                    &nbsp;
                </el-col>
                <el-col :span="8" style="text-align: left;padding-top: 20px">
                    <el-form :model="reviewForm" ref="reviewForm" label-width="80px" :rules="rules">
                        <el-form-item label="审核人" prop="auditor">
                            <el-input v-model="reviewForm.auditor"></el-input>
                        </el-form-item>
                        <el-form-item label="审核意见" prop="auditAdvice">
                            <el-input v-model="reviewForm.auditAdvice" type="textarea" :rows="2"></el-input>
                        </el-form-item>
                        <el-form-item label=" ">
                            <el-button type="primary" :loading="confirmLoading" @click="reviewConfirm('SUCCESS')">通过</el-button>
                            <el-button type="danger" :loading="confirmLoading" @click="reviewConfirm('FAILED')">驳回</el-button>
                        </el-form-item>
                    </el-form>
                </el-col>
                <el-col :span="14">
                    &nbsp;
                </el-col>
              </el-row>
            </el-dialog>
        </el-card>
    </section>
</template>

<script>
    export default {
        name: "ReviewContent",
        props: {
            currentTask: {
                type: Object,
            },
            isHasTask: {
                type: Boolean
            }
        },
        data() {
            return {
                confirmLoading: false,
                tabContentLoading: false,
                confirmIndexLoading: false,
                unactiveIndex: 0,
                activeIndex: 0,
                finishList: [],
                unFinishList: [],
                recipet: [],
                form: {},
                formRules: {
                    name: [
                        { required: true, message: '请输入确认人姓名', trigger: 'blur' },
                    ],
                },
                reviewForm: {
                  auditor: '',
                  auditAdvice: ''
                },
                rules:{
                    auditor: [
                        { required: true, message: '审核人不能为空', trigger: 'blur' }
                    ],
                    auditAdvice: [
                        { required: true, message: '审核意见不能为空', trigger: 'blur' }
                    ]
                },
                currentTaskObject: {},
                contentLoad:false,
                tabIndex: 0,
                tabList: [],
                districtId: '',
                parentQuotaId: '',
                isSetWeight: '',
                checkVisible: false,
                isDepart: '',
                towns: [],
                townsList: []
            }
        },
        watch: {
            'isHasTask': {
                handler: function () {
                    this.loadAllTaskObject();
                }
            },
            'currentTask.id': {
                handler: function() {
                    this.loadAllTaskObject();
                }
            },
            tabIndex: function (newVal) {
              let scrollNav = document.getElementById('tabUl')
              let tabBar = document.getElementById('tabBar')
              let transformHeight = scrollNav.scrollHeight - tabBar.clientHeight
              if (Number(newVal) >= 3) {
                this.$nextTick(function () {
                  scrollNav.style.transform = `translateY(-${transformHeight}px)`
                })
              } else {
                this.$nextTick(function () {
                 scrollNav.style.transform = 'translateY(0px)'
                })
              }
            }
        },
        methods: {
            async loadAllTaskObject() {
                if (!this.isHasTask) {
                    return ;
                }
                this.finishList = [];
                this.unFinishList = [];
                let data = await this.$http("POST", '/identity/cadreTaskObject/list?sort=status,asc', {taskId: this.currentTask.id}, false);
                data.forEach(item => {
                  if ( item && item.status == '2' || item.status =='3') {
                    this.finishList.push(item);
                  } else if (item.status == '0' || item.status =='1') {
                    this.unFinishList.push(item);
                  }
                });
                if (this.unFinishList.length !== 0 ) {
                  await this.updateIndex(this.unFinishList[0], 0);
                } else {
                  await this.updateIndex(this.finishList[0], 0)
                }
            },
            async updateIndex(item, index) {
              if (item.status == '0' || item.status == '1') {
                this.unactiveIndex = index;
                this.activeIndex = -1;
              } else {
                this.activeIndex = index;
                this.unactiveIndex = -1;
              }
              this.tabIndex = 0;
              this.contentLoad = true;
              this.currentTaskObject = item;
              const res = await this.$http('POST', `identity/kpiQuota/list`, {quotaMakeDepartId: item.objectId, quotaLevel: '1', quotaYear: this.currentTask.taskYear}, false);
              this.tabList = res;
              this.districtId = item.objectId;
              this.isDepart = item.objectType.indexOf('Depart')>-1?'1':'0';
              await this.changeTab(this.tabIndex, this.tabList[0]);
              this.contentLoad = false;
            },
            showCheckDialog() {
              this.checkVisible = true;
              this.$nextTick(function () {
                this.$refs['reviewForm'].resetFields();
              })
            },
            reviewConfirm(value) {
              this.$refs['reviewForm'].validate(async (valid) => {
                if(valid) {
                  this.confirmLoading = true;
                  this.contentLoad = true;
                  await this.$http("GET", `/identity/cadreTaskObject/progressNext?taskObjectId=${this.currentTaskObject.id}&isSuccess=${value}&auditor=${this.reviewForm.auditor}&auditAdvice=${this.reviewForm.auditAdvice}`, false);
                  this.$message({
                      type: 'success',
                      message: value == "SUCCESS" ? '审核成功！' : '驳回成功！'
                  })
                  this.$emit('refreshConfirmList');
                  await this.loadAllTaskObject();
                  this.confirmLoading = false;
                  this.contentLoad = false
                  this.checkVisible = false
                }
              })
            },
            confirmIndex(form){
                if(this.unFinishList.length==0){
                    this.$refs.form.validate(async (valid) => {
                        if (valid) {
                          this.confirmIndexLoading = true;
                          await this.$http('GET', `/identity/cadreTaskObject/quota/confirm?taskId=${this.currentTask.id}`,  false).then(() => {
                            this.$message({
                              type: 'success',
                              message: '确认成功'
                            })
                          })
                          this.confirmIndexLoading = false;
                          this.$parent.getTaskList();
                        } else {
                            return false;
                        }
                    });
                }else{
                    this.$message({
                        type:'warning',
                        message:'指标还未全部制定完成，无法确认！'
                    })
                }
            },
            // 更改tab页签
            async changeTab (index, item, townType) {
              this.tabContentLoading = true;
              this.tabIndex = index;
              this.isSetWeight = item.isSetWeight ? item.isSetWeight : '';
              let param = {districtId: this.districtId, parentQuotaId: item.quotaId};
              const res = await this.$http('post',`identity/kPITownQuota/getAll?isDepart=${this.isDepart}`, param, false);
              this.recipet = res;
              this.tabContentLoading = false;
            },
            getTownsList(){
              const townsList = {}
              for(let key in this.towns) {
                townsList[this.towns[key].districtName] = this.towns[key]
              }
              this.townsList = townsList;
              console.log(this.townsList, 'this.townsList');
            },
        },
        created() {
          this.loadAllTaskObject();
          this.towns = JSON.parse(sessionStorage.getItem("towns"));
          this.getTownsList();
        }
    }
</script>
<style lang="less" scoped>
    .box {
      position: relative;
      padding: 12px 15px 20px 0;
      border: 1px solid #ccc;
      z-index: 0;
      border-radius: 0 4px 4px 4px;
    }
    .content_box {
      .unchecked {
        position: relative;
        bottom: -1px;
        height: 320px;
        border-bottom: 1px solid #fff;
        border-radius: 4px 4px 0 0;
        z-index: 99;
      }
    }
    .unchecked,
    .checked {
      float: left;
      width: 47%;
      height: 300px;
      padding-top: 10px;
      border: 1px solid #ccc;
      border-radius: 4px;
      .review_title {
        margin-left: 10px;
        font-weight:bold;
        color:rgba(57,57,57,1);
        line-height:38px;
        p {
          float: left;
          font-size: 16px;
          color: #393939;
        }
        span {
          float: left;
          font-size: 24px;
        }
      }
    }
    .unchecked .review_title {
      span {
        color: #DC143C;
      }
    }
    .checked .review_title {
      span {
        color: #0A9B1A;
      }
    }
    .unchecked_item,
    .checked_item {
      position: relative;
      float: left;
      margin-left: 10px;
      margin-top: 10px;
      width: 175px;
      height: 50px;
      color: #55BD94;
      line-height: 50px;
      border-radius: 4px;
      cursor: pointer;
    }
    .checked_item {
      background-color: #F1FFF3;
      border: 1px solid #55BD94;
    }
    .uncommit {
      background:#F2F2F2;
      border:1px solid #DFDFDF;
      color: #7E7E7E;
    }
    .unreview {
      background:#F1FFF3;
      border:1px solid #55BD94;
    }
    .mark {
      position: absolute;
      right: -1px;
      top: -1px;
      width:34px;
      height:34px;
    }
    .active_bgc {
      background-color: #55BD94;
      border:1px solid rgba(85, 189, 148, 1);
      color: #fff;
    }
    .uncommit_mark {
      background: url("../../static/img/uncommit.png");
    }
    .unreview_mark {
      background: url("../../static/img/unreview.png");
    }
    .checked_mark {
      background-image: url("../../static/img/checked.png");
    }
    .active_uncommit_mark {
      background-image: url("../../static/img/active_uncommit.png");
    }
    .active_unreview_mark {
      background-image: url("../../static/img/active_unreview.png");
    }
    .active_checked_mark {
      background: url("../../static/img/active_checked.png");
    }
    .arrow {
      float: left;
      width: 6%;
      height: 300px;
      background: url("../../static/img/review-arrow.png") no-repeat center center;
    }
    .confirm_input {
      float: right;
      margin-right: 25px;
      .el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
        margin-bottom: 0;
      }
      .el-form-item__label {
        font-size: 15px;
        line-height: 35px;

      }
      .cofirm_form,
      .confirmBtn {
        float: left;
      }
      .confirmBtn {
        .el-button {
          width:80px;
          height:34px;
          background:rgba(85,189,148,1);
          border: none;
          margin-left: 14px;
        }
      }
    }
    .indicator_header, .indicator_body {
      height: 40px;
      border-radius: 5px;
      line-height: 40px;
      text-align: left;
      margin-top: 10px;
       div {
          padding-left: 20px;
          display: inline-block;
       }
         :nth-child(1) {
           width: 249px;
         }
         :nth-child(2) {
           width: 130px;
         }
         :nth-child(3) {
           width: 60px;
         }
    }
    .indicator_body {
      background-color: #ddf1e834;
      border: 1px solid #ddf1e834;
      box-shadow: 2px 2px 10px 2px #ddf1e834;
      margin: 10px 10px 0 10px;
      div {
        padding-left: 10px;
      }
      :nth-child(3) {
        padding-left: 20px;
      }
    }
    .check_button .el-button{
      text-align: center;
      font-size: 16px;
      float: left;
      margin-left: 20px;
      width:98px;
      height:40px;
      background:rgba(85,189,148,1);
      border: none;
    }
    .second_level_day {
      width: 1500px;
      margin: 20px 20px 0 20px;
      .item_title {
        border-left: 4px solid #36BC5B;
        background-image: linear-gradient(to right, #F0FDF4 , #fff);
        height: 40px;
        text-align: left;
        line-height: 40px;
        padding-left: 10px;
        font-size: 20px;
        font-weight: 700;
      }
      .actual_table {
        margin: 20px 0 20px 30px;
        border: none;
        border-right: 1px solid #eee;
        border-bottom: 1px solid #eee;
        td {
        border-top: 1px solid #eee;
        border-left: 1px solid #eee;
        height: 30px;
        padding: 0 8px;
        }
        tr:hover {
            background: #eff;
        }
      }
    }
    .second_level_day:nth-child(1) {
      margin-top: 0;
    }
    .not_available {
      margin-top: 40px;
      width: 100%;
      p {
        width: 100%;
        font-size: 20px;
        text-align: center;
      }
    }
</style>

<style lang="less">
.ReviewContent {
  // padding: 20px;
  .tabWrap{
    overflow: hidden;
    width:100%;
    .tabNav{
      width:100%;
      height: 100%;
      float: left;
      #tabBar{
        background-color: transparent;
        position: relative;
        right: -1px;
        float: left;
        height:e("calc(100% - 60px)");
        overflow: hidden;
        z-index: 999;
        #tabUl{
          float: right;
          width: 52px;
          transition: -webkit-transform .5s ease-in-out;
          transition: transform .5s ease-in-out;
          .tabLi {
            right: -1px;
            width: 100%;
            font-size: 16px;
            writing-mode: vertical-lr;
            padding: 10px 0 10px 15px;
            cursor: pointer;
            border: 1px solid #dedede;
            margin-bottom: 5px;
            border-radius: 5px 0 0 6px;
            text-align: center;
            vertical-align: middle;
            background: #f8f8f8;
            letter-spacing: 2px;
              font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
              box-shadow: inset -10px 0px 10px -10px #eaeaea;
          }
          .tabLi:hover{
            color:#2d8cf0;
          }
        .activeTab{
            position: relative;
            z-index: 999;
            color:#2d8cf0;
            background: #ffffff;
            box-shadow: none;
          }
        }
      }
      .iconClass{
        display: inline-block;
        height: 30px;
        margin-left: 8px;
        cursor: pointer;
        text-align: center;
        line-height: 30px;
        width: e("calc(100% - 10px)");
      }
    }
    .tabContent{
      border-radius: 0 5px 5px 5px;
      border: 1px solid #dedede;
      float:left;
      overflow: auto;
      min-height: 950px;
      padding-top: 30px;
      background-color: #fff;
      box-shadow: -3px -3px 20px -10px #eaeaea;
      .tabContent_one {
          min-height: 950px;
          overflow: hidden;
      }
      .second_level_day {
        .el-card__body {
          padding: 0;
        }
      }
      .second_level {
        float: left;
        margin: 0 0 30px 23px;
        width: 490px;
        .is-always-shadow {
          box-shadow: none;
          .el-card__body {
            min-height: 400px;
            padding: 0;
            .item_title {
              border-left: 4px solid #36BC5B;
              background-image: linear-gradient(to right, #F0FDF4 , #fff);
              height: 40px;
              text-align: left;
              line-height: 40px;
              padding-left: 10px;
              font-size: 20px;
              font-weight: 700;
            }
            .three_level {
              .three_level_item {
                cursor: pointer;
                float: left;
                font-size: 16px;
                width: 135px;
                height: 80px;
                margin-top: 25px;
                margin-left: 15px;
                .three_level_title {
                  width: 130px;
                  color: #262626;
                  // text-overflow: ellipsis;
                  // white-space: nowrap;
                  // overflow: hidden;
                }
                .three_level_score {
                  margin-bottom: 15px;
                  font-size: 14px;
                  color: #aaa;
                  span {
                    font-size: 28px;
                    color: #FD4B63;
                    font-weight: 700;
                  }
                }
              }
              .three_level_item:nth-child(2n) {
                .three_level_score {
                  div {
                    height: 32px;
                  }
                  span {
                    color: #0692EB;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
  li {
    list-style: none;
  }

  .content_box {
    box-shadow: none;
    border-bottom:1px solid rgba(10, 155, 26, 1) !important;
    border-left:1px solid rgba(10, 155, 26, 1) !important;
    border-right:1px solid rgba(10, 155, 26, 1) !important;
    border-top: none;
    border-radius: 0 0 4px 4px!important;
  }
  .content_box.el-card {
    border: none;
  }
  .el-tag--dark.el-tag--danger,
  .el-tag--dark.el-tag--warning,
  .el-tag--dark.el-tag--primary,
  .el-tag--dark.el-tag--success {
    margin-left: 18px;
  }

  .cofirm_form {
    .el-input__inner {
      height: 35px;
    }
    .el-form-item--mini .el-form-item__content, .el-form-item--mini .el-form-item__label {
      line-height: 35px;
    }
    .el-form-item__label {
      font-size: 16px;
      vertical-align: bottom;
    }
  }
</style>
<style>
  .table_box::-webkit-scrollbar-thumb {
      background-color: #5EC79E!important;
  }
  .table_box::-webkit-scrollbar  {
    height: 12px  /*滚动条高度*/
  }

  .check_button .el-button--primary.is-disabled, 
  .check_button .el-button--primary.is-disabled:active, 
  .check_button .el-button--primary.is-disabled:focus, 
  .check_button .el-button--primary.is-disabled:hover {
    background-color: #55bd94;
    border-color: #55bd94;
  }
</style>
